package com.xwn.provider.dubbo;

import com.alibaba.dubbo.config.annotation.Service;
import com.xwn.api.service.IUserApi;
import com.xwn.bean.entity.User;
import com.xwn.provider.mapper.IUserMapper;
import com.xwn.provider.repository.UserRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

/**
 * 用户Service实现
 * @Author duandw
 * @Date 2019/11/19 10:17
 **/
@org.springframework.stereotype.Service
@Service(interfaceClass = IUserApi.class)
@Slf4j
public class UserApiImpl implements IUserApi {

    @Autowired
    private IUserMapper userMapper;

    @Autowired
    private UserRepository userRepository;

    @Override
    public User findUserByNamePass(String userName, String password) {
        return null;
    }

    @Override
    public User findUserByName(String username) {
        return userMapper.findUserByName(username);
    }

    @Override
    public User updateUser(User user) {
        user.preUpdate(user);
        user.setLastLoginDate(new Date());
        return userRepository.saveAndFlush(user);
    }
}
